import axiosApi from '@/axios'

export default class RestApi {
  static get reqBaseUrl () {
    return '/api';
  }

  static get globalBaseUrl () {
    return {
      enums: `${this.reqBaseUrl}/oauth/enums`,
      upload: `${this.reqBaseUrl}/oauth/oss/open/Fileuploading`
    }
  }

  static loadEnums (data) {
    let { codes, enums = {} } = data;
    if (typeof (codes) === 'string') {
      codes = [codes]
    }
    if (codes && codes.length > 0) {
      const url = this.globalBaseUrl.enums
      return axiosApi({
        method: 'GET',
        url,
        data: { codes: codes }
      }).then(res => {
        for (const code of codes) {
          enums[code] = Object.assign(enums[code], res.data[code])
        }
        return enums
      })
    }
  }

}
